<?php
 include_once('../src/classes/class.mssql.php');
 session_start();
 $db = new MSSQL();
 $comtec_id_machine = $_GET['comtec_id_machine'];
 $comtec_id_operation = $_GET['comtec_id_operation'];
 $token = $_GET['token'];
 
 $result = $db->fetch_array($db->query("SELECT cod_mainteiner,comtec_id_configman FROM machines WHERE comtec_id_machine = $comtec_id_machine"));   
 $cod_mainteiner = $result['cod_mainteiner'];
 $comtec_id_configman = $result['comtec_id_configman'];
 
$result = $db->fetch_array($db->query(
     "SELECT (r.name+' '+r.lastname1+' '+r.lastname2) as encargado,o.operation_type,
       CONVERT(varchar,m.date_next_maintenance,103) as date_next,
       CONVERT(varchar,o.operation_date_start,103) as operation_date1,
       CONVERT(varchar,o.operation_date_start,114) as operation_time1, 
       CONVERT(varchar,o.operation_date_end,103) as operation_date2, 
       CONVERT(varchar,o.operation_date_end,114) as operation_time2,  
       o.diagnosis,o.changed_parts,o.value_parts,o.value_work,o.value_others,o.value_total,o.notes,o.notes_for_owner,
       o.delay,s.name_s
      FROM ((operation as o 
       INNER JOIN machines as m ON o.comtec_id_machine = m.comtec_id_machine) 
       INNER JOIN responsible as r ON o.comtec_id_responsible = r.comtec_id_responsible)
       INNER JOIN status_op as s ON s.id_s = o.comtec_id_status 
      WHERE o.comtec_id_operation = $comtec_id_operation"
));  
 $operation_type = $result['operation_type'];
 $encargado = $result['encargado'];
 
 $diagnosis = $result['diagnosis'];
 $changed_parts = $result['changed_parts'];
 $notes = $result['notes'];
 
 $date_next = $result['date_next'];
 $operation_date1 = $result['operation_date1'];
 $operation_time1 = $result['operation_time1'];
 $operation_time1 = substr($operation_time1,0,5);
 $operation_date2 = $result['operation_date2'];
 $operation_time2 = $result['operation_time2'];
 $operation_time2 = substr($operation_time2,0,5);
 $delay = $result['delay'];
 
 $value_parts = $result['value_parts'];
 $value_work = $result['value_work'];
 $value_others = $result['value_others'];
 $value_total = $result['value_total'];
 
 $notes_for_owner = $result['notes_for_owner'];
 $status = $result['name_s'];
 
     switch ($operation_type) {
      case 1: 
             $operation_type = "Mantenci&oacute;n";
      break;
      case 2: 
             $operation_type = "Emergencia";
      break; 
      case 3: 
             $operation_type = "Instalaci&oacute;n";
      break;
      case 4:
             $operation_type = "Reparaci&oacute;n";
      break;
     }

?>
<fieldset class="curved">
 <legend>Ver</legend>
 <table style="margin: 10px auto; border-spacing: 10px;">
        <tr>
             <td width="200">M&aacute;quina</td>
             <td>
                <input type="text" DISABLED size="40" value="<?=$cod_mainteiner?>">
             </td>
        </tr>
        <tr>
             <td width="200">Tipo de operaci&oacute;n</td>
             <td>
                 <input type="text" DISABLED size="40" value="<?=$operation_type?>">
             </td>
             <td width="200">Encargado</td>
             <td colspan="4">
                 <input type="text" DISABLED size="40" value="<?=$encargado?>">
             </td>
        </tr>
        <? if($_SESSION['users']!="clients"){ ?>
        <tr>
             <td width="200">Diagn&oacute;stico</td>
             <td colspan=4><textarea rows="2" cols="91" readonly="readonly" style="resize:none"><?=$diagnosis?></textarea></td>
        </tr>
            <tr>
               <td width="200">Repuestos cambiados</td>
               <td colspan=4><textarea rows="2" cols="91" readonly="readonly" style="resize:none"><?=$changed_parts?></textarea></td>
            </tr>
            <tr>
                <td width="200">Notas</td> 
                <td colspan=4><textarea rows="2" cols="91" readonly="readonly" style="resize:none"><?=$notes?></textarea></td>
            </tr>
            <? }?>
            <tr>
               <td width="200">Fecha prox. Mantenci&oacute;n</td>
               <td>
                   <input type="text" size="40" DISABLED value="<?=$date_next?>">
               </td>
            </tr>
           <? if($_SESSION['users']=="administratives-2" || $_SESSION['users']=="managers"){ ?>
           <tr>
                <td width="200">Valor mano de obra</td>
                <td>
                    <input type="text" DISABLED size="40" value="<?=$value_work?>">
                </td> 
                <td width="200">Valores repuestos</td>
                <td>
                    <input type="text" DISABLED size="40" value="<?=$value_parts?>">
                </td>
           </tr>
           <tr>
                <td width="200">Otros valores</td>
                <td><input type="text" DISABLED size="40" value="<?=$value_others?>"></td>
                <td width="200">Valor total</td>
                <td><input type="text" DISABLED size="40" value="<?=$value_total?>"></td>
           </tr>
           <?}?>
           <? if($_SESSION['users']!="clients"){ ?>
           <tr>              
               <td width="200">Fecha de inicio</td>
               <td>
                   <input type="text" DISABLED size="40" value="<?=$operation_date1?>">
               </td>
               <td width="200">Hora de inicio</td>
               <td>
                   <input type="text" DISABLED size="40" value="<?=$operation_time1?>">
               </td>
           </tr>
           <? }?>
           <tr>
               <td width="200">
                Fecha de fin
               </td>
               <td>
                   <input type="text" DISABLED size="40" value="<?=$operation_date2?>">
               </td>
               <td width="200">
               Hora de fin
               </td>   
               <td>
                   <input type="text" DISABLED size="40" value="<?=$operation_time2?>">
               </td> 
           </tr>
           <? if($_SESSION['users']=="administratives-2" || $_SESSION['users']=="managers"){ ?>
           <tr>
               <td width="200">Demora</td>
               <td>
                   <input type="text" DISABLED size="40" value="<?=$delay?>">
               </td>
           </tr>
           <?}?>
           <tr>              
               <td>Notas para cliente</td>
               <td colspan=4><textarea rows="2" cols="91" readonly="readonly" style="resize:none"><?=$notes_for_owner?></textarea></td>
           </tr>
            <? if($_SESSION['users']!="clients"){ ?>
            <tr>
                <td width="200">Estado</td>
                <td>
                    <input type="text" size="40" DISABLED value=<?=$status?> >
                </td>
            </tr>
            <? }?>
            <tr><td><input type="button" value="Regresar" onclick="javascript:goBackSearch();" /></td></tr>
          </table> 
</fieldset>
